<?php
class alarm extends spModel
{
	var $pk = "alarmid";
	var $table = "alarm";
	
	  var $linker = array(
		array(
			'type' => 'hasone',
			'map' => 'site',
			'mapkey' => 'siteid',	
			'fclass' => 'site',
			'fkey' => 'siteid',
			'enabled' => true ,
			'field' => 'domain, title'	
		),
	);
  


	function a_alarm($conditions)
	{
		$conditions= array
		(
			"user_id" => $_SESSION["userinfo"]["userid"],
		);
		$n = $this->spLinker()->findAll($conditions);
		return $n;
	}
	function s_time($conditions)
	{
		$sort = "alarmid DESC ";
		$limit = "1";
		$n = $this->findAll($conditions,$sort,$fields,$limit);
		return $n;
	}
	//获取当月的记录
	function n_moth()
	{
		$d_time = spClass('my_fun');
		$t = date("Y-m-d H:i:s",strtotime("0 month"));		
		$f = $d_time->GetTheMonth($t);
		$b = strtotime($f[0]);
		$a = strtotime($f[1]);

		$conditions = "addtime between '$b' and '$a'";
		$n = $this->findAll($conditions, 'addtime DESC');
		
		return $n;
	}
	//获取上月的记录
	function n1_moth()
	{
		$d_time = spClass('my_fun');
		$t = date("Y-m-d H:i:s",strtotime("-1 month"));		
		$f = $d_time->GetTheMonth($t);
		$b = strtotime($f[0]);
		$a = strtotime($f[1]);
		$conditions = "addtime between '$b' and '$a'";
		$n = $this->findAll($conditions);
		return $n;
	}
	//获取第N个月的记录
	function n2_moth($n, $page = 1, $pageSize = 10)
	{
//		$d_time = spClass('my_fun');
//		$t = date("Y-m-d H:i:s",strtotime("$n month"));		
//		$f = $d_time->GetTheMonth($t);
//		$b = strtotime($f[0]);
//		$a = strtotime($f[1]);
		$userid = $_SESSION["userinfo"]["userid"];
		$conditions = "user_id='$userid' ";
		$result['list'] = $this->spLinker()->spPager($page, $pageSize)->findAll($conditions, 'addtime DESC');
		$result['pagedata'] = $this->spPager()->getPager();
		return $result;
	}
	//获取指定时间段得记录

	function nmoth($b,$a, $page = 1, $pageSize = 10)
	{
		$userid = $_SESSION["userinfo"]["userid"];
		$conditions = "baomu_alarm.addtime between '$b' and '$a'  and user_id='$userid'";
		$n = $this->spLinker()->spPager($page, $pageSize)->findAll($conditions, 'addtime DESC');
		$this->pagedata = $this->spPager()->getPager();
		return $n;
	}

}